<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="招标类型" prop="projectTypeId">
        <el-select v-model="queryParams.projectTypeId" clearable placeholder="请选择">
          <el-option
            v-for="item in projecttypeList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="招标方式" prop="projectTenderModeId">
        <el-select v-model="queryParams.projectTenderModeId" clearable placeholder="请选择">
          <el-option
            v-for="item in projecttendermodeList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="所属部门" prop="projectDeptId">
        <treeselect v-model="queryParams.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 200px"/>
      </el-form-item>

      <el-form-item label="资质主体" prop="projectAgencyId">
        <el-input
          v-model="queryParams.projectAgencyId"
          placeholder="请输入资质主体"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="资金来源" prop="projectFundingSourceId">
        <el-select v-model="queryParams.projectFundingSourceId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectfundingsourceList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="委托业主" prop="projectTenderee">
        <el-input
          v-model="queryParams.projectTenderee"
          placeholder="请输入委托业主"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评标时间" prop="projectBidMakeTime">
        <el-date-picker clearable
          v-model="queryParams.projectBidMakeTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择评标时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:expertselect:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:expertselect:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:expertselect:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:expertselect:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="expertselectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="left" prop="id" />
      <el-table-column label="项目名称" align="left" prop="projectName" />
      <el-table-column label="项目编号" align="left" prop="projectCode" />
      <el-table-column label="招标类型" align="left" prop="projectTypeName" />
      <el-table-column label="招标方式" align="left" prop="projectTenderModeName" />
      <el-table-column label="所属部门" align="left" prop="projectDeptName" />
      <el-table-column label="评标方法" align="left" prop="projectBidevaluationModeName" />
      <el-table-column label="资金来源" align="left" prop="projectFundingSourceName" />
      <el-table-column label="委托业主" align="left" prop="projectTenderee" />
      <el-table-column label="评标时间" align="left" prop="projectBidMakeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.projectBidMakeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="资质主体" align="left" prop="projectAgencyName" />
      <el-table-column label="抽取专家数" align="left" prop="projectSectionQty" />
      <el-table-column label="业主代表数" align="left" prop="projectBidderQty" />
      <el-table-column label="状态" prop="status"  width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1">抽取已保存</el-tag>
          <el-tag v-if="scope.row.status === 2" type="success">抽取已确认</el-tag>
          <el-tag v-if="scope.row.status === 0" type="info">待抽取</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.extractedNum > 0"
            @click="showExpertExtract(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status != 2"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status != 2"
            @click="handleExpertExtract(scope.row)"
          >专家抽取</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专家抽取对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" style="max-height: 400px; overflow-y: scroll;">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectCode">
              <el-input v-model="form.projectCode" placeholder="请输入项目编号" style="width: 280px" >
                <el-button slot="append" @click="showProject" icon="el-icon-search">选择项目</el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="招标类型" prop="projectTypeId">
              <el-select v-model="form.projectTypeId" @change="selectProjectType" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projecttypeList"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标方式" prop="projectTenderModeId">
              <el-select v-model="form.projectTenderModeId" @change="selectProjectTenderMode" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projecttendermodeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="评标方法" prop="projectBidevaluationModeId">
              <el-select v-model="form.projectBidevaluationModeId" @change="selectProjectBidevaluationMode" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projectbidevaluationmodeList"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资金来源" prop="projectFundingSourceId">
              <el-select v-model="form.projectFundingSourceId" @change="selectProjectFundingSource" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projectfundingsourceList"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="委托业主" prop="projectTendereeId">
              <el-input :disabled="true" v-model="form.projectTenderee" placeholder="请选择招标人" style="width: 280px">
                <el-button slot="append" @click="showProjectTenderee" type="success" icon="el-icon-search">选择</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="所属部门" prop="projectDeptId">
              <treeselect @select="selectProjectDept" v-model="form.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 280px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资质主体" prop="projectAgencyId">
              <el-select v-model="form.projectAgencyId" @change="selectProjectAgency" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projectagencyList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="评标时间" prop="projectBidMakeTime">
              <el-date-picker clearable
                v-model="form.projectBidMakeTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择评标时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评标地址" prop="projectBidMakeAddr">
              <el-input v-model="form.projectBidMakeAddr" placeholder="请输入评标地址" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="专家抽取地区" prop="areaId">
              <el-select v-model="form.areaId" @change="selectProjectArea" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in companyAreaList"
                  :key="item.areaId"
                  :label="item.areaName"
                  :value="item.areaId">

                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="抽取专家数" prop="projectSectionQty">
              <el-input v-model="form.projectSectionQty" placeholder="请输入抽取专家数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业主代表数" prop="projectBidderQty">
              <el-input v-model="form.projectBidderQty" placeholder="请输入业主代表数" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-form-item label="抽取专家类别" prop="projectExpertCategoryName">

            <el-select v-model="categoryId" multiple placeholder="请选择" @change="handleExpertCategoryChange">
                <el-option
                  v-for="item in moreExpertCategory"
                  :key="item.categoryId"
                  :label="item.categoryName"
                  :value="item.categoryId">
                </el-option>
            </el-select>
            <el-button @click="handleCategory" icon="el-icon-search">选择类别</el-button>


            <!-- el-input v-model="form.projectExpertCategoryName" placeholder="请输入抽取专家类别"  >
              <el-button slot="append" @click="handleCategory" icon="el-icon-search">选择专家类别</el-button>
            </el-input -->
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="回避单位" prop="tendererId">
            <el-select v-model="tendererId" multiple placeholder="请选择" @change="handleTendererChange">
                <el-option
                  v-for="item in moreTenderer"
                  :key="item.tendererId"
                  :label="item.tendererName"
                  :value="item.tendererId">
                </el-option>
            </el-select>
            <el-button @click="handleTenderer" icon="el-icon-search">选择单位</el-button>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="回避专家" prop="noExpertId">
            <el-select v-model="noExpertId" multiple placeholder="请选择" @change="handleNoExpertChange">
                <el-option
                  v-for="item in moreNoExpert"
                  :key="item.expertId"
                  :label="item.expertName"
                  :value="item.expertId">
                </el-option>
            </el-select>
            <el-button @click="handleNoExpert" icon="el-icon-search">选择专家</el-button>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="自定义专家组" prop="expertCustomGroupId">
            <el-select v-model="expertCustomGroupId" multiple placeholder="请选择" @change="handleExpertCustomGroupChange">
                <el-option
                  v-for="item in moreExpertCustomGroup"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
            </el-select>
            <el-button @click="handleExpertCustomGroup" icon="el-icon-search">选择专家组</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 项目列表 -->
    <el-dialog :title="projectTitle" :visible.sync="openProject" width="70%" append-to-body>
        <el-form :model="queryProjectParams" ref="queryProjectForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="项目编号" prop="projectCode">
            <el-input
              v-model="queryProjectParams.projectCode"
              placeholder="请输入项目编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="项目名称" prop="projectName">
            <el-input
              v-model="queryProjectParams.projectName"
              placeholder="请输入项目名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="项目部门" prop="projectDeptId">
            <treeselect v-model="queryProjectParams.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 200px"/>
          </el-form-item>
          <el-form-item label="资质主体" prop="projectAgencyId">
            <el-select v-model="queryProjectParams.projectAgencyId"  clearable placeholder="请选择" >
              <el-option
                v-for="item in projectagencyList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleProjectQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetProjectQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="projectList">
          <el-table-column label="ID" width="40" align="center" prop="id" />
          <el-table-column label="项目编号" align="left" width="160" prop="projectCode" />
          <el-table-column label="项目名称" align="left" width="160" prop="projectName" />
          <el-table-column label="所属部门" align="center" prop="projectDeptName" />
          <el-table-column label="委托单位" align="left" width="200" prop="projectTenderee" />
          <el-table-column label="立项时间" align="left" width="200" prop="createTime" />
          <el-table-column label="开标时间" align="left" width="200" prop="projectBidOpenTime" />
          <el-table-column label="资质主体" align="left" width="200" prop="projectAgencyName" />
          <el-table-column label="操作" fixed="right" width="120" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleSelectProject(scope.row)"
              >选择</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="projectTotal>0"
          :total="projectTotal"
          :page.sync="queryProjectParams.pageNum"
          :limit.sync="queryProjectParams.pageSize"
          @pagination="getProjectList"
        />

    </el-dialog>

    <el-dialog
      width="70%"
      :title="formInnerTitle"
      :visible.sync="formInnerVisible"
      append-to-body>
      <Tenderer v-if="formInnerType  === 'projectTenderee'" :getTendererRow="getProjectTendereeRow" />
    </el-dialog>

    <!-- 专家品目列表弹窗 -->
    <el-dialog :title="categoryTitle" :visible.sync="categoryOpen" width="80%" append-to-body>

      <el-form :model="categoryParams" ref="queryCategoryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

        <el-form-item label="品目编码" prop="categoryCode">
          <el-input
            v-model="categoryParams.categoryCode"
            placeholder="请输入品目编码"
            clearable
            @keyup.enter.native="handleCategoryQuery"
          />
        </el-form-item>
        <el-form-item label="品目名称" prop="categoryName">
          <el-input
            v-model="categoryParams.categoryName"
            placeholder="请输入品目名称"
            clearable
            @keyup.enter.native="handleCategoryQuery"
          />
        </el-form-item>


        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleCategoryQuery">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="categoryList">
        <el-table-column label="品目ID" align="center" prop="id" />
        <el-table-column label="父ID" align="center" prop="pid" />
        <el-table-column label="品目编码" align="center" prop="categoryCode" />
        <el-table-column label="品目名称" align="center" prop="categoryName" />
        <el-table-column label="品目说明" align="center" prop="categoryDes" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleSelectCategory(scope.row)"
            >选择</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="categoryTotal>0"
        :total="categoryTotal"
        :page.sync="categoryParams.pageNum"
        :limit.sync="categoryParams.pageSize"
        @pagination="categoryList"
      />
    </el-dialog>

    <!-- 回避单位列表弹窗 -->
    <el-dialog :title="tendererTitle" :visible.sync="tendererOpen" width="80%" append-to-body>
      <el-form :model="queryTendererParams" ref="queryTendererForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="招标人" prop="tendererName">
          <el-input
            v-model="queryTendererParams.tendererName"
            placeholder="请输入招标人名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="所属部门" prop="deptId">
          <el-input
            v-model="queryTendererParams.deptId"
            placeholder="请输入所属部门ID"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleTendererQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetTendererQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="tendererList">
        <el-table-column label="招标人ID" align="center" prop="id" />
        <el-table-column label="招标人" align="center" prop="tendererName" />
        <el-table-column label="统一社会信用代码" align="center" prop="unifiedSocialCreditCode" />
        <el-table-column label="法定代表人" align="center" prop="legalRepresentative" />
        <el-table-column label="注册资本" align="center" prop="registeredCapital" />
        <el-table-column label="邮箱" align="center" prop="email" />
        <el-table-column label="经营范围" align="center" prop="businessScope" />
        <el-table-column label="传真" align="center" prop="fax" />
        <el-table-column label="电话" align="center" prop="tel" />
        <el-table-column label="地址" align="center" prop="addr" />
        <el-table-column label="状态" align="center" prop="status" />
        <el-table-column label="所属部门ID" align="center" prop="deptId" />
        <el-table-column label="所属部门名称" align="center" prop="deptName" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleSelectTenderer(scope.row)"
            >选择</el-button>

          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="tendererTotal>0"
        :total="tendererTotal"
        :page.sync="queryTendererParams.pageNum"
        :limit.sync="queryTendererParams.pageSize"
        @pagination="getTendererList"
      />
    </el-dialog>


    <!-- 回避专家列表弹窗 -->
    <el-dialog :title="expertTitle" :visible.sync="expertOpen" width="80%" append-to-body>
        <el-form :model="queryExpertParams" ref="queryExpertForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="专家姓名" prop="expertName">
            <el-input
              v-model="queryExpertParams.expertName"
              placeholder="请输入专家姓名"
              clearable
              @keyup.enter.native="handleExpertQuery"
            />
          </el-form-item>
          <el-form-item label="证件类型" prop="identityTypeId">
            <el-select v-model="queryExpertParams.identityTypeId" clearable placeholder="请选择">
                <el-option
                  v-for="item in identitytypeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
          </el-form-item>
          </el-form-item>

          <el-form-item label="地区" prop="areaId">
            <el-select v-model="queryExpertParams.areaId" clearable placeholder="请选择">
                <el-option
                  v-for="item in companyareaList"
                  :key="item.areaId"
                  :label="item.areaName"
                  :value="item.areaId">
                </el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="专家类型" prop="expertTypeId">
            <el-select v-model="queryExpertParams.expertTypeId" clearable placeholder="请选择">
                <el-option
                  v-for="item in experttypeList"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleExpertQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetExpertQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="expertList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="ID" align="center" prop="id" />
          <el-table-column label="专家姓名" align="center" prop="expertName" />
          <el-table-column label="手机号码" align="center" prop="mobile" />
          <el-table-column label="证件类型" align="center" prop="identityTypeName" />
          <el-table-column label="证件号码" align="center" prop="identityCode" />
          <el-table-column label="地区" align="center" prop="areaName" />
          <el-table-column label="专家类型" align="center" prop="expertTypeName" />
          <el-table-column label="性别" align="center" prop="sex" />
          <el-table-column label="邮箱" align="center" prop="email" />
          <el-table-column label="专家品目" align="center" prop="expertCategoryName" />
          <el-table-column label="是否在职" align="center" prop="isOnJob" />
          <el-table-column label="最高学历" align="center" prop="highestEducation" />
          <el-table-column label="职务" align="center" prop="postition" />

          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleSelectExpert(scope.row)"
              >选择</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="expertTotal>0"
          :total="expertTotal"
          :page.sync="queryExpertParams.pageNum"
          :limit.sync="queryExpertParams.pageSize"
          @pagination="getList"
        />
    </el-dialog>


    <!-- 自定义专家组列表弹窗 -->
    <el-dialog :title="expertCustomTitle" :visible.sync="expertCustomOpen" width="80%" append-to-body>
      <el-form :model="queryExpertCustomParams" ref="queryExpertCustomForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="专家组" prop="expertGroupName">
          <el-input
            v-model="queryExpertCustomParams.expertGroupName"
            placeholder="请输入专家组名称"
            clearable
            @keyup.enter.native="handleExpertCustomQuery"
          />
        </el-form-item>
        <el-form-item label="所属部门" prop="projectDepartment">
          <el-input
            v-model="queryExpertCustomParams.projectDepartment"
            placeholder="请输入项目所属部门"
            clearable
            @keyup.enter.native="handleExpertCustomQuery"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="queryExpertCustomParams.remark"
            placeholder="请输入备注"
            clearable
            @keyup.enter.native="handleExpertCustomQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleExpertCustomQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetExpertCustomQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="expertcustomgroupList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="left" />
        <el-table-column label="ID" width="55" align="left" prop="id" />
        <el-table-column label="专家组名称" align="left" prop="expertGroupName" />
        <el-table-column label="项目所属部门" align="left" prop="projectDepartment" />
        <el-table-column label="专家数量" align="left" prop="expertNum" />
        <el-table-column label="备注" align="left" prop="remark" />
        <el-table-column label="添加日期" align="left" prop="createTime" />
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-add"
              @click="handleSelectExpertCustomGroup(scope.row)"
            >设置</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="expertcustomTotal>0"
        :total="expertcustomTotal"
        :page.sync="queryExpertCustomParams.pageNum"
        :limit.sync="queryExpertCustomParams.pageSize"
        @pagination="getExpertCustomGroupList"
      />
    </el-dialog>


    <!-- 专家抽取弹窗 -->
    <el-dialog :title="expertExtractTitle" :visible.sync="expertExtractOpen" width="80%" append-to-body>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              size="mini"
              :disabled="doExpertExtractDisabled"
              @click="doExpertExtract"
            >专家抽取</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              size="mini"
              :disabled="reDoExpertExtractDisabled"
              @click="reDoExpertExtract"
            >补抽</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              size="mini"
              :disabled="resetExpertExtractDisabled"
              @click="resetExpertExtract"
            >重置</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              size="mini"
              @click="confirmExpertExtract"
            >确认</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="expertExtractList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="left" />
          <el-table-column label="抽取轮次" align="left" prop="number" />
          <el-table-column label="专家姓名" align="left" prop="expertName" />
          <el-table-column label="证件号码" align="left" prop="expert.identityCode" />
          <el-table-column label="手机号码" align="left" prop="expert.mobile" />
          <el-table-column label="职称" align="left" prop="expert.technicaTitle" />
          <el-table-column label="状态" align="left" prop="status"  width="80">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status == '1'">出席</el-tag>
              <el-tag v-if="scope.row.status == '0'" type="info">缺席</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                v-if="scope.row.status == '1'"
                @click="setNoStatus(scope.row)"
              >缺席</el-button>
              <el-button
                size="mini"
                type="text"
                v-if="scope.row.status == '0'"
                @click="setYesStatus(scope.row)"
              >签到</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="expertExtractTotal>0"
          :total="expertExtractTotal"
          :page.sync="queryExpertExtractParams.pageNum"
          :limit.sync="queryExpertExtractParams.pageSize"
          @pagination="getProjectExpertExtractList"
        />
    </el-dialog>

    <!-- 查看 -->
    <el-dialog :title="extractResultTitle" :visible.sync="extractResultOpen" width="60%" append-to-body>

      <el-form class="print-content" ref="print" label-width="120px" size="mini" style="1px solid #dfe6ec;" v-if="expertSelect != null">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号：">{{expertSelect.projectCode}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*项目名称：">{{expertSelect.projectName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*招标类型：">{{expertSelect.projectTypeName}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*招标方式：">{{expertSelect.projectTenderModeName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*评标方法：">{{expertSelect.projectBidevaluationModeName}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*资金来源：">{{expertSelect.projectFundingSourceName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*委托业主：">{{expertSelect.projectTenderee}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*项目所属部门：">{{expertSelect.projectDeptName}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="资质主体：">{{expertSelect.projectAgencyName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*评标时间：">{{expertSelect.projectBidMakeTime}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*评标地址：">{{expertSelect.projectBidMakeAddr}}</el-form-item>
          </el-col>
        </el-row>

        <el-row v-for="(p,index) of extractResult">
          <p v-if="p">第 {{index}} 轮抽取</p>
          <el-table
              v-if="p"
              :data="p"
              border
              style="width: 100%">
              <el-table-column
                align="left"
                prop="expert.expertName"
                label="专家姓名"
                width="80">
              </el-table-column>
              <el-table-column
                align="left"
                width="200"
                prop="expert.identityCode"
                label="证件号码"
                >
              </el-table-column>
              <el-table-column
                align="left"
                prop="expert.mobile"
                label="手机号码"
                width="120">
              </el-table-column>
              <el-table-column
                align="left"
                prop="expert.technicaTitle"
                label="职称"
                >
              </el-table-column>
              <el-table-column
                align="left"
                label="专家状态"
                width="80">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.status === '0'" type="info">缺席</el-tag>
                  <el-tag v-if="scope.row.status === '1'" type="success">出席</el-tag>
                </template>
              </el-table-column>
            </el-table>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="extractResultOpen = false">关 闭</el-button>
        <el-button @click="onPrint">打 印</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listExpertselect, getExpertselect, delExpertselect, addExpertselect, updateExpertselect,doExpertselectextract } from "@/api/system/expertselect";
import { listExpertcategory, getExpertcategory, delExpertcategory, addExpertcategory, updateExpertcategory, changeExpertcategoryStatus } from "@/api/system/expertcategory";
import { listTenderer, getTenderer, delTenderer, addTenderer, updateTenderer } from "@/api/system/tenderer";
import { listExpertcustomgroup, getExpertcustomgroup, delExpertcustomgroup, addExpertcustomgroup, updateExpertcustomgroup } from "@/api/system/expertcustomgroup";
import { listProjectexpertextract, listsProjectexpertextract, getProjectexpertextract, delProjectexpertextract, addProjectexpertextract, updateProjectexpertextract,setProjectexpertextractstatus,resetProjectexpertextract,confirmExpertselectextract} from "@/api/system/projectexpertextract";
import { listProject} from "@/api/system/project";
import { listsBidder } from "@/api/system/bidder";
import { listsProjectpayer } from "@/api/system/projectpayer";
import { listsProjectbidevaluationprocess } from "@/api/system/projectbidevaluationprocess";
import { listsProjecttendermode } from "@/api/system/projecttendermode";
import { listsProjecttype } from "@/api/system/projecttype";
import { listsProjectbidevaluationmode } from "@/api/system/projectbidevaluationmode";
import { listsProjectfundingsource } from "@/api/system/projectfundingsource";
import { listsCompany } from "@/api/system/company";
import { listsCompanyarea } from "@/api/system/companyarea";
import { deptTreeSelect } from "@/api/system/user";
import { listsIdentitytype } from "@/api/system/identitytype";
import { listsExpertcategory } from "@/api/system/expertcategory";
import { listsType } from "@/api/system/experttype";
import { listsCompanytype } from "@/api/system/companytype";
import { listExpert, getExpert, delExpert, addExpert, updateExpert } from "@/api/system/expert";

import print from '@/utils/print.js';
import Treeselect from "@riophae/vue-treeselect";
import Tenderer from "@/components/Tenderer";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import User from "@/components/User";

export default {
  name: "Expertselect",
  components: {User, Treeselect,Tenderer },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      projectTotal: 0,
      // 专家抽取表格数据
      expertselectList: [],
      projectList: [],
      projecttypeList: [],
      projecttendermodeList: [],
      projectbidevaluationmodeList: [],
      projectfundingsourceList: [],
      // 资质主体
      projectagencyList: [],
      deptList: [],
      companyAreaList: [],
      // 专家管理表格数据
      expertList: [],
      // 地区列表
      companyareaList: [],
      // 身份类型列表
      identitytypeList: [],
      // 专家品目列表
      expertcategoryList: [],
      // 专家类型列表
      experttypeList: [],
      // 企业类型列表
      companytypeList: [],
      // 弹出层标题
      title: "",
      projectTitle: "",
      tendererTitle: "",
      // 是否显示弹出层
      open: false,
      openProject: false,
      tendererOpen: false,
      formInnerVisible:false,
      formInnerType:null,
      formInnerTitle:null,
      categoryTitle: "",
      // 项目是否显示弹出层
      categoryOpen: false,
      // 总条数
      categoryTotal: 0,
      // 专家品目表格数据
      categoryList: [],
      tendererList: [],
      tendererTotal: 0,
      expertTitle: "",
      expertOpen: false,
      moreNoExpert: [],
      noExpertId: [],
      noExpertName: [],

      // 专家
      expertTotal: 0,

      // 自定义专家组列表弹窗
      expertCustomTitle: "",
      expertCustomOpen: false,
      expertCustomGroupId: [],
      expertCustomGroupName: [],
      moreExpertCustomGroup: [],
      queryExpertCustomParams: {
        pageNum: 1,
        pageSize: 10,
        expertGroupName: null,
        projectDepartment: null,
        projectDepartmentId: null,
        remark: null,
        params:{}
      },
      expertcustomgroupList: [],
      expertcustomTotal: 0,


      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        projectCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        status: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectBidMakeTime: null,
        projectBidMakeAddr: null,
        projectSectionQty: null,
        projectBidderQty: null,
        projectExpertCategoryId: null,
        projectExpertCategoryName: null,
        noExpertId: null,
        noExpertName: null,
        expertCustomGroupId: null,
        expertCustomGroupName: null,
        sort: null,
      },
      queryProjectParams: {
        pageNum: 1,
        pageSize: 10,
        projectCode: null,
        projectName: null,
        projectDeptId: null,
        projectAgencyId: null
      },
      categoryParams: {
        pageNum: 1,
        pageSize: 10,
        pid: null,
        categoryCode: null,
        categoryName: null,
        categoryDes: null,
        categorySort: null,
        enabled: null,
      },
      queryTendererParams: {
        pageNum: 1,
        pageSize: 10,
        tendererName: null,
        unifiedSocialCreditCode: null,
        legalRepresentative: null,
        registeredCapital: null,
        email: null,
        licenseSrc: null,
        businessScope: null,
        fax: null,
        tel: null,
        addr: null,
        status: null,
        deptId: null,
        deptName: null,
      },
      queryExpertParams: {
        pageNum: 1,
        pageSize: 10,
        expertName: null,
        mobile: null,
        identityTypeId: null,
        identityTypeName: null,
        identityCode: null,
        areaId: null,
        areaName: null,
        expertTypeId: null,
        expertTypeName: null,
        sex: null,
        email: null,
        expertCategoryId: null,
        expertCategoryName: null,
        isOnJob: null,
        workCompany: null,
        graduatedFrom: null,
        highestEducation: null,
        technicaTitle: null,
        postition: null,
        addr: null,
        isJoinExpertDb: null,
        status: null,
        bankName: null,
        bankAccount: null,
        attachmentOtherImage: null,
        attachmentImage: null,
        professionalTypeSelect: null,
        categoryCodeRemark: null,
        workingYears: null,
        userName: null,
        password: null,
        pwdPlaintext: null,
        approvalStatus: null,
        approvalRemark: null,
        fromType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      moreExpertCategory: [],
      categoryId: [],
      categoryName: [],
      moreTenderer: [],
      tendererId: [],
      tendererName: [],

      // -- 专家抽取弹窗 --
      expertSelect: null,
      doExpertExtractDisabled: true,
      reDoExpertExtractDisabled: true,
      resetExpertExtractDisabled: true,
      expertSelectId: null,
      expertExtractTitle: '',
      expertExtractOpen: false,
      expertExtractList: [],
      expertExtractTotal: 0,
      // 查询参数
      queryExpertExtractParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        expertSelectId: null,
        expertId: null,
        expertName: null,
        number: null,
        status: null,
      },


      // -------------------  查看抽取结果  -------------------
      extractResultTitle: '',
      extractResultOpen: false,
      extractResult:[],

    };
  },
  created() {
    this.getList();
    this.getProjectList();
    this.getProjecttypeList();
    this.getProjecttendermodeList();
    this.getProjectbidevaluationmodeList();
    this.getProjectfundingsourceList();
    this.getDeptTree();
    this.getListsCompany();
    this.getCompanyAreaList();
    this.getCategoryList();
    this.getTendererList();
    this.getIdentitytypeList();
    this.getExpertCategoryList();
    this.getExpertTypeList();
    this.getExpertList();
    this.getExpertCustomGroupList();
  },
  methods: {
    /** 查询专家抽取列表 */
    getList() {
      this.loading = true;
      listExpertselect(this.queryParams).then(response => {
        this.expertselectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getProjectList() {
      this.loading = true;
      listProject(this.queryProjectParams).then(response => {
        this.projectList = response.rows;
        this.projectTotal = response.total;
        this.loading = false;
      });
    },
    getProjecttypeList() {
      this.loading = true;
      listsProjecttype(this.queryParams).then(response => {
        this.projecttypeList = response.data;
        this.loading = false;
      });
    },
    getProjecttendermodeList() {
      this.loading = true;
      listsProjecttendermode(this.queryParams).then(response => {
        this.projecttendermodeList = response.data;
        this.loading = false;
      });
    },
    getProjectbidevaluationmodeList() {
      this.loading = true;
      listsProjectbidevaluationmode(this.queryParams).then(response => {
        this.projectbidevaluationmodeList = response.data;
        this.loading = false;
      });
    },
    getProjectfundingsourceList() {
      this.loading = true;
      listsProjectfundingsource(this.queryParams).then(response => {
        this.projectfundingsourceList = response.data;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptList = response.data;
      });
    },
    getListsCompany() {
      this.loading = true;
      listsCompany(this.queryParams).then(response => {
        this.projectagencyList = response.data;
        this.loading = false;
      });
    },
    getCompanyAreaList() {
      this.loading = true;
      listsCompanyarea(this.queryParams).then(response => {
        this.companyAreaList = response.data;
        this.companyareaList = response.data;
        this.loading = false;
      });
    },
    /** 查询专家品目列表 */
    getCategoryList() {
      this.loading = true;
      listExpertcategory(this.categoryParams).then(response => {
        this.categoryList = response.rows;
        this.categoryTotal = response.total;
        this.loading = false;
      });
    },
    getTendererList() {
      this.loading = true;
      listTenderer(this.tendererParams).then(response => {
        this.tendererList = response.rows;
        this.tendererTotal = response.total;
        this.loading = false;
      });
    },
    /**获取身份类型列表**/
    getIdentitytypeList(){
      this.loading = true;
      listsIdentitytype(this.queryParams).then(response => {
        this.identitytypeList = response.data;
        this.loading = false;
      });
    },
    /**获取专家品目列表**/
    getExpertCategoryList(){
      this.loading = true;
      listsExpertcategory(this.queryParams).then(response => {
        this.expertcategoryList = response.data;
        this.loading = false;
      });
    },
    /**获取专家型列表**/
    getExpertTypeList(){
      this.loading = true;
      listsType(this.queryParams).then(response => {
        this.experttypeList = response.data;
        this.loading = false;
      });
    },
    /** 查询专家管理列表 */
    getExpertList() {
      this.loading = true;
      listExpert(this.queryParams).then(response => {
        this.expertList = response.rows;
        this.expertTotal = response.total;
        this.loading = false;
      });
    },
    /** 自定义专家组 **/
    getExpertCustomGroupList(){
      this.loading = true;
      listExpertcustomgroup(this.queryParams).then(response => {
        this.expertcustomgroupList = response.rows;
        this.expertcustomTotal = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        projectName: null,
        projectCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        status: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectBidMakeTime: null,
        projectBidMakeAddr: null,
        projectSectionQty: null,
        projectBidderQty: null,
        projectExpertCategoryId: null,
        projectExpertCategoryName: null,
        noExpertId: null,
        noExpertName: null,
        expertCustomGroupId: null,
        expertCustomGroupName: null,
        sort: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    showProject(){
      this.projectTitle = "从已有项目中选择";
      this.openProject = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleProjectQuery() {
      this.queryProjectParams.pageNum = 1;
      this.getProjectList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetProjectQuery() {
      this.resetForm("queryProjectForm");
      this.handleProjectQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加专家抽取";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExpertselect(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专家抽取";
        // 设置其他参数
        if(this.form.projectExpertCategoryId != null || this.form.projectExpertCategoryId != ''){
            this.categoryId = this.form.projectExpertCategoryId.split(',');
            this.categoryName = this.form.projectExpertCategoryName.split(',');
            this.moreExpertCategory = [];
            for (var i = 0; i < this.categoryId .length; i++) {
              this.moreExpertCategory.push({'categoryName': this.categoryName[i], 'categoryId': this.categoryId[i]});
            }
        }else{
          this.categoryId = [];
          this.categoryName = [];
        }

        if(this.form.noExpertId != null || this.form.noExpertId != ''){
          this.noExpertId = this.form.noExpertId.split(',');
          this.noExpertName = this.form.noExpertName.split(',');
          this.moreNoExpert = [];
          for (var i = 0; i < this.noExpertId.length; i++) {
              this.moreNoExpert.push({'expertName': this.noExpertName[i], 'expertId': this.noExpertId[i]});
          }
        }else{
          this.noExpertId = [];
          this.noExpertName = [];
        }

        if(this.form.tendererId != null || this.form.tendererId != ''){
          this.tendererId = this.form.tendererId.split(',');
          this.tendererName = this.form.tendererName.split(',');
          this.moreTenderer = [];
          for (var i = 0; i < this.tendererId.length; i++) {
              this.moreTenderer.push({'tendererName': this.tendererName[i], 'tendererId': this.tendererId[i]});
          }
        }else{
          this.tendererId = [];
          this.tendererName = [];
        }

        if(this.form.expertCustomGroupId != null || this.form.expertCustomGroupId != ''){
          this.expertCustomGroupId = this.form.expertCustomGroupId.split(',');
          this.expertCustomGroupName = this.form.expertCustomGroupName.split(',');
          this.moreExpertCustomGroup = [];
          for (var i = 0; i < this.expertCustomGroupId.length; i++) {
              this.moreExpertCustomGroup.push({'name': this.expertCustomGroupName[i], 'id': this.expertCustomGroupId[i]});
          }
        }else{
          this.expertCustomGroupId = [];
          this.expertCustomGroupName = [];
           this.moreExpertCustomGroup = [];
        }
      });
    },
    handleSelectProject(row){
      console.log(row)
      this.openProject = false;
      this.form.projectCode = row.projectCode;
      this.form.projectId = row.id;
      this.form.projectName = row.projectName;
      this.form.projectTypeId = row.projectTypeId;
      this.form.projectTypeName = row.projectTypeName;
      this.form.projectTenderModeId = row.projectTenderModeId;
      this.form.projectTenderModeName = row.projectTenderModeName;
      this.form.projectBidevaluationModeId = row.projectBidevaluationModeId;
      this.form.projectBidevaluationModeName = row.projectBidevaluationModeName;
      this.form.projectFundingSourceId = row.projectFundingSourceId;
      this.form.projectFundingSourceName = row.projectFundingSourceName;
      this.form.projectTendereeId = row.projectTendereeId;
      this.form.projectTenderee = row.projectTenderee;
      this.form.projectDeptId = row.projectDeptId;
      this.form.projectDeptName = row.projectDeptName;
      this.form.projectAgencyId = row.projectAgencyId;
      this.form.projectAgencyName = row.projectAgencyName;
      this.form.projectBidMakeTime = row.projectBidMakeTime;
      this.form.projectBidMakeAddr = row.projectBidMakeAddr;
      this.form.projectSectionQty = row.projectSectionQty;
      this.form.projectBidderQty = row.projectBidderQty;
      //this.form.projectBidOpenAddr = row.projectBidOpenAddr;
      this.form.projectBidMakeAddr = row.projectBidOpenAddr;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {

          if(this.categoryId.length >0){
            this.form.projectExpertCategoryId = this.categoryId.join(",");
            this.form.projectExpertCategoryName = this.categoryName.join(",");
          }else{
            this.form.projectExpertCategoryId = '';
            this.form.projectExpertCategoryName = '';
          }

          if(this.noExpertId.length > 0){
            this.form.noExpertId = this.noExpertId.join(",");
            this.form.noExpertName = this.noExpertName.join(",");
          }else{
            this.form.noExpertId = '';
            this.form.noExpertName = '';
          }

          if(this.tendererId.length > 0){
            this.form.tendererId = this.tendererId.join(",");
            this.form.tendererName = this.tendererName.join(",");
          }else{
            this.form.tendererId = '';
            this.tendererName = '';
          }

          if(this.expertCustomGroupId.length >0){
            this.form.expertCustomGroupId = this.expertCustomGroupId.join(",");
            this.form.expertCustomGroupName = this.expertCustomGroupName.join(",");
          }else{
            this.form.expertCustomGroupId = '';
            this.form.expertCustomGroupName = '';
          }

          if (this.form.id != null) {
            updateExpertselect(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExpertselect(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除专家抽取编号为"' + ids + '"的数据项？').then(function() {
        return delExpertselect(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/expertselect/export', {
        ...this.queryParams
      }, `expertselect_${new Date().getTime()}.xlsx`)
    },


    // 项目相关
    handleCategory(){
      this.categoryOpen = true;
      this.categoryTitle = "选择父级专家品目";
    },
    selectProjectType(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projecttypeList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectTypeName = selectedOption.text;
      }
    },
    selectProjectTenderMode(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projecttendermodeList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectTenderModeName = selectedOption.name;
      }
    },
    selectProjectBidevaluationMode(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectbidevaluationmodeList.find(option => option.id === value);

      if (selectedOption) {
        this.form.projectBidevaluationModeName = selectedOption.text;
      }
    },
    selectProjectFundingSource(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectfundingsourceList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectFundingSourceName = selectedOption.text;
      }
    },
    selectProjectAgency(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectagencyList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectAgencyName = selectedOption.name;
      }
    },
    selectProjectArea(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.companyAreaList.find(option => option.areaId === value);
      if (selectedOption) {
        this.form.projectAreaName = selectedOption.areaName;
      }
    },
    showProjectTenderee(){
      this.formInnerVisible = true;
      this.formInnerTitle = "选择委托业主";
      this.formInnerType = "projectTenderee";
    },
    getProjectTendereeRow(row){
      this.form.projectTendereeId =row.id;
      this.form.projectTenderee =row.tendererName;
      this.formInnerVisible = false;
    },
    handleCategoryQuery() {
      this.categoryParams.pageNum = 1;
      this.getCategoryList();
    },
    selectProjectDept(value) {
      console.log(value)
      this.form.projectDeptName = value.label;
    },
    handleSelectCategory(row){
      //this.form.projectExpertCategoryId = row.id;
      //this.form.projectExpertCategoryName = row.categoryName;
      this.categoryOpen=false;
      this.moreExpertCategory.push({'categoryName': row.categoryName, 'categoryId': row.id });
      // 过滤重复
      this.moreExpertCategory = this.moreExpertCategory.filter((item, index, self) =>
          index === self.findIndex((t) => t.categoryId === item.categoryId)
      );

      let ids = [];
      let names = [];
      this.moreExpertCategory.forEach((item,index)=>{
          ids.push(item['categoryId']);
          names.push(item['categoryName']);
      });
      this.categoryId = ids;
      this.categoryName = names;
      console.log(this.moreExpertCategory)
    },
    handleExpertCategoryChange(value) {
      console.log('Selected values changed to:', value);
      // 这里可以执行其他逻辑
      if(value.length > 0){
        /*
        for (let i = 0; i < value.length; i++) {
          // 遍历数组，对每个元素进行操作
          console.log(arr[i]);
        }*/
        let ids = [];
        let names = [];
        let newMoreExpertCategory = this.moreExpertCategory.filter(item=>{
            return value.includes(item.categoryId);
        }).map(item=>{
            ids.push(item['categoryId']);
            names.push(item['categoryName']);
            return item;
        });
        this.categoryName = names;
        this.moreExpertCategory = newMoreExpertCategory;
      }else{
        this.moreExpertCategory = [];
        this.categoryId = [];
        this.categoryName = [];
      }
    },
    handleTenderer(){
      this.tendererOpen = true;
      this.tendererTitle = "选择回避单位";
    },
    handleTendererChange(value) {
      console.log('Selected values changed to:', value);
      // 这里可以执行其他逻辑
      if(value.length > 0){
        let ids = [];
        let names = [];
        let newMoreTenderer = this.moreTenderer.filter(item=>{
            return value.includes(item.tendererId);
        }).map(item=>{
            ids.push(item['tendererId']);
            names.push(item['tendererName']);
            return item;
        });
        this.tendererName = names;
        this.moreTenderer = newMoreTenderer;
      }else{
        this.moreTenderer = [];
        this.tendererId = [];
        this.tendererName = [];
      }
    },
    /** 重置按钮操作 */
    resetTendererQuery() {
      this.resetForm("queryTendererForm");
      this.handleTendererQuery();
    },

    /** 搜索按钮操作 */
    handleTendererQuery() {
      this.queryTendererParams.pageNum = 1;
      this.getTendererList();
    },
    handleSelectTenderer(row){
      this.tendererOpen=false;
      this.moreTenderer.push({'tendererName': row.tendererName, 'tendererId': row.id });
      // 过滤重复
      this.moreTenderer = this.moreTenderer.filter((item, index, self) =>
          index === self.findIndex((t) => t.tendererId === item.tendererId)
      );
      let ids = [];
      let names = [];
      this.moreTenderer.forEach((item,index)=>{
          ids.push(item['tendererId']);
          names.push(item['tendererName']);
      });
      this.tendererId = ids;
      this.tendererName = names;
    },
    /** 搜索按钮操作 */
    handleExpertQuery() {
      this.queryExpertParams.pageNum = 1;
      this.getExpertList();
    },
    /** 重置按钮操作 */
    resetExpertQuery() {
      this.resetForm("queryExpertForm");
      this.handleExpertQuery();
    },
    handleNoExpert(){
      this.expertOpen = true;
      this.expertTitle = "选择回避专家";
    },
    handleSelectExpert(row){
      this.expertOpen=false;
      this.moreNoExpert.push({'expertName': row.expertName, 'expertId': row.id });
      // 过滤重复
      this.moreNoExpert = this.moreNoExpert.filter((item, index, self) =>
          index === self.findIndex((t) => t.expertId === item.expertId)
      );
      let ids = [];
      let names = [];
      this.moreNoExpert.forEach((item,index)=>{
          ids.push(item['expertId']);
          names.push(item['expertName']);
      });
      this.noExpertId = ids;
      this.noExpertName = names;
    },
    handleNoExpertChange(value){
        // 这里可以执行其他逻辑
        if(value.length > 0){
          let ids = [];
          let names = [];
          let newMoreNoExpert = this.moreNoExpert.filter(item=>{
              return value.includes(item.noExpertId);
          }).map(item=>{
              ids.push(item['expertId']);
              names.push(item['expertName']);
              return item;
          });
          this.noExpertName = names;
          this.moreNoExpert = newMoreNoExpert;
        }else{
          this.moreNoExpert = [];
          this.noExpertId = [];
          this.noExpertName = [];
        }
    },

    // ------------------------------------------------------ 自动专家组 --------------------------
    handleExpertCustomGroup(){
      this.expertCustomTitle = "选择自定义专家组";
      this.expertCustomOpen = true;
    },
    /** 重置按钮操作 */
    resetExpertCustomQuery() {
      this.resetForm("queryExpertCustomForm");
      this.handleExpertCustomQuery();
    },
    /** 搜索按钮操作 */
    handleExpertCustomQuery() {
      this.queryExpertCustomParams.pageNum = 1;
      this.getExpertCustomGroupList();
    },
    handleExpertCustomGroupChange(value) {
      // 这里可以执行其他逻辑
      if(value.length > 0){
        let ids = [];
        let names = [];
        let newMoreExpertCustomGroup = this.moreExpertCustomGroup.filter(item=>{
            return value.includes(item.id);
        }).map(item=>{
            ids.push(item['id']);
            names.push(item['name']);
            return item;
        });
        this.expertCustomGroupId = value;
        this.expertCustomGroupName = names;
        this.moreExpertCustomGroup = newMoreExpertCustomGroup;
      }else{
        this.moreExpertCustomGroup = [];
        this.expertCustomGroupId = [];
        this.expertCustomGroupName = [];
      }
    },
    handleSelectExpertCustomGroup(row){
      this.expertCustomOpen=false;
      this.moreExpertCustomGroup.push({'name': row.expertGroupName, 'id': row.id });
      // 过滤重复
      this.moreExpertCustomGroup = this.moreExpertCustomGroup.filter((item, index, self) =>
          index === self.findIndex((t) => t.id === item.id)
      );
      let ids = [];
      let names = [];
      this.moreExpertCustomGroup.forEach((item,index)=>{
          ids.push(item['id']);
          names.push(item['name']);
      });
      this.expertCustomGroupId = ids;
      this.expertCustomGroupName = names;
    },
    // 专家抽取
    handleExpertExtract(row){
      this.expertExtractTitle = '专家抽取';
      this.expertExtractOpen = true;
      this.expertSelectId = row.id;
      this.expertSelect = row;
      this.doExpertExtractDisabled = true;
      this.reDoExpertExtractDisabled = true;
      this.resetExpertExtractDisabled = true;
      console.log(this.expertSelect)
      this.queryExpertExtractParams.expertSelectId = row.id;
      // 抽取列表
      this.getProjectExpertExtractList();
    },
    // 专家抽取列表
    getProjectExpertExtractList()
    {
      this.loading = true;
      listProjectexpertextract(this.queryExpertExtractParams).then(response => {
        this.expertExtractList = response.rows;
        this.expertExtractTotal = response.total;

        getExpertselect(this.expertSelectId).then(response => {
          this.expertSelect = response.data;

          if(this.expertExtractTotal == 0){
            this.doExpertExtractDisabled = false;
          }else{
            this.resetExpertExtractDisabled = false;
            var extractedNum = 0;
            for (var row of this.expertExtractList) {
              if(row.status == 1 || row.status == '1'){
                extractedNum = extractedNum + 1;
              }
            }
            this.reDoExpertExtractDisabled = true;
            if(extractedNum < this.expertSelect.projectSectionQty){
              this.reDoExpertExtractDisabled = false;
            }else{
              this.doExpertExtractDisabled = true;
            }
          }
        });
        this.loading = false;
      });
    },
    // 点击专家抽取
    doExpertExtract(){
      const id = this.expertSelectId;
      console.log(id)
      this.$modal.confirm('是否确定抽取专家？').then(function() {
        return doExpertselectextract(id);
      }).then(() => {
        this.getProjectExpertExtractList();
        this.$modal.msgSuccess("抽取成功");
      }).catch(() => {});
    },
    // 重置专家抽取
    resetExpertExtract(){
      const id = this.expertSelectId;
      console.log(id)
      this.$modal.confirm('是否确定重置专家抽取？').then(function() {
        return resetProjectexpertextract(id);
      }).then(() => {
        this.getProjectExpertExtractList();
        this.$modal.msgSuccess("重置专家抽取成功");
      }).catch(() => {});
    },
    // 补抽
    reDoExpertExtract(){
      const id = this.expertSelectId;
      console.log(id)
      this.$modal.confirm('是否确定补抽？').then(function() {
        return doExpertselectextract(id);
      }).then(() => {
        this.getProjectExpertExtractList();
        this.$modal.msgSuccess("补抽成功");
      }).catch(() => {});
    },
    // 确认抽取
    confirmExpertExtract(){
      const id = this.expertSelectId;
      console.log(id)
      this.$modal.confirm('是否确认抽取？').then(function() {
        return confirmExpertselectextract(id);
      }).then(() => {
        this.getProjectExpertExtractList();
        this.$modal.msgSuccess("确认成功");
      }).catch(() => {});
    },
    // 设置缺席
    setNoStatus(row){
      const id = row.id;
      this.$modal.confirm('是否确设置‘缺席’？').then(function() {
        return setProjectexpertextractstatus(id,0);
      }).then(() => {
        this.getProjectExpertExtractList();
        this.$modal.msgSuccess("设置成功");
      }).catch(() => {});
    },
    // 设置出席
    setYesStatus(row){
      const id = row.id;
      this.$modal.confirm('是否确设置‘缺席’？').then(function() {
        return setProjectexpertextractstatus(id,1);
      }).then(() => {
        this.getProjectExpertExtractList();
        this.$modal.msgSuccess("设置成功");
      }).catch(() => {});
    },

    //-------------------  查看专家抽取  -----------------
    showExpertExtract(row){
      console.log(row)
      // 查询抽取结果
      this.extractResult = [];
      this.expertSelect = row;
      console.log(this.expertSelect)
      this.queryExpertExtractParams.expertSelectId = row.id;
      listsProjectexpertextract(this.queryExpertExtractParams).then(response => {
        if(response.data.length > 0){
          for (var extractData of response.data) {
            if(!this.extractResult[extractData['number']]){
              this.extractResult[extractData['number']] = [];
              //this.extractResult[extractData['number']] = [extractData];
              this.extractResult[extractData['number']].push(extractData);
            }else{
              this.extractResult[extractData['number']].push(extractData);
            }
          }
          this.extractResultTitle = '查看';
          this.extractResultOpen = true;
        }
      });
      console.log(this.extractResult)
    },
    // 打印
    onPrint() {
      print(this.$refs.print);
    },

  }
};
</script>
